package com.myrpc.handler;

import com.myrpc.common.Req;
import com.myrpc.common.Res;
import com.myrpc.service.ProviderMgr;

import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @User: weiyi.liu
 * @Date: 2018-06-08
 * @Time: 22:02
 */
public class RpcServiceHandler extends SimpleChannelInboundHandler<Req> {

	protected void channelRead0(ChannelHandlerContext ctx, Req req) {
		Object object = ProviderMgr.invoke(req);
		Res res = new Res(req.getId(), object);
		ctx.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
	}
}
